#coding=utf-8
'''
数据处理静态方法
'''
import datetime

def deal_datetime(date=str):
    '''
    处理日期格式

    :Args:
     - date: 输入数据中的原始日期格式

    :Returns:
        返回统一的日期格式：year/month/day
    '''
    try:
        date = datetime.datetime.strptime(date,"%Y%m%d")
    except ValueError:
        try:
            date = datetime.datetime.strptime(date, "%Y-%m-%d")
        except ValueError:
            date = datetime.datetime.strptime(date, "%Y/%m/%d")
    return date.strftime("%Y/%m/%d")

def deal_time(time=str):
    '''
    处理时间格式

    :Args:
     - time: 输入数据中的原始时间格式

    :Returns:
        返回统一的日期格式：hour:minute:second
    '''
    try:
        time = datetime.datetime.strptime(time, "%H:%M:%S")
    except ValueError:
        time = datetime.datetime.strptime(time, "%H:%M")
    return time.strftime("%H:%M:%S")

def split_datetime(date=str):
    '''
    拆分日期

    :Args:
     - date: 输入数据中的原始日期格式

    :Returns:
        返回year，month，day
    '''
    text = deal_datetime(date)
    date_text_list = text.split('/')
    if len(date_text_list) == 1:
        year = date_text_list[0]
        month = '01'
        day = '01'
    elif len(date_text_list) == 2:
        year = date_text_list[0]
        month = date_text_list[1]
        day = '01'
    elif len(date_text_list) == 3:
        year = date_text_list[0]
        month = date_text_list[1]
        day = date_text_list[2]
    else:
        raise AttributeError('日期参数不符合日期规范！')
    return year, month, day

def split_time(time=str):
    '''
    拆分时间

    :Args:
     - time: 输入数据中的原始时间格式

    :Returns:
        返回hour，minute，second
    '''
    text = deal_time(time)
    time_text_list = text.split(':')
    if len(time_text_list) == 1:
        hour = time_text_list[0]
        minute = '00'
        second = '00'
    elif len(time_text_list) == 2:
        hour = time_text_list[0]
        minute = time_text_list[1]
        second = '00'
    elif len(time_text_list) == 3:
        hour = time_text_list[0]
        minute = time_text_list[1]
        second = time_text_list[2]
    else:
        raise AttributeError('时间参数不符合日期规范！')
    return hour, minute, second